package com.ledi.guns.modular.ledipay.controller;

import io.swagger.annotations.Api;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.shiro.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ledi.guns.common.annotion.Permission;
import com.ledi.guns.common.persistence.model.vo.RoutesVo;
import com.ledi.guns.core.base.controller.BaseController;
import com.ledi.guns.core.base.tips.SuccessTip;
import com.ledi.guns.modular.system.service.IRoutesService;

/**
 * 文件名称： com.ledi.guns.modular.ledipay.controller.MenuController.java<br/>
 * 初始作者： 钟小平<br/>
 * 创建日期： 2018年1月29日<br/>
 * 功能说明： 路由 <br/>
 * =================================================<br/>
 * 修改记录：<br/>
 * 修改作者 日期 修改内容<br/>
 * ================================================<br/>
 * Copyright (乐迪教育科技有限公司-幼儿事业部) 2017-2018.All rights reserved.<br/>
 */
@Api
@RestController
@RequestMapping("/routesMenu")
public class MenuRoleController extends BaseController {

	@Resource
	private IRoutesService iRoutesService;

	/**
	 * 获取菜单列表
	 */
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	@Permission
	public Object list(@RequestParam(required = false) Long roleId) {

		Assert.notNull(roleId);
		List<RoutesVo> menus = iRoutesService.selectMenus(roleId);
		return SuccessTip.buildSuccess(menus);
	}

	/**
	 * @api {GET} /routesMenu/authority 平台角色权限
	 * @apiVersion 1.4.0
	 * @apiGroup routesMenu
	 * @apiName authority
	 * @apiParam {int} type 类型（0，学校1，员工，2代理商 ）
	 * @apiSuccess {int} id 反馈id
	 * @apiSuccess {int} code 返回编码（200成功）
	 * @apiSuccess {String} message 返回说明
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "data": {
	 *                    "学校管理员": [
	 *                    "首页",
	 *                    "缴费账单发送",
	 *                    "当面付",
	 *                    "缴费账单明细",
	 *                    "意见反馈"
	 *                    ],
	 *                    "老师": [
	 *                    "首页",
	 *                    "缴费账单发送",
	 *                    "当面付",
	 *                    "用户管理",
	 *                    "短信管理",
	 *                    "缴费账单明细",
	 *                    "意见反馈"
	 *                    ]
	 *                    },
	 *                    "message": "成功"
	 *                    }
	 */
	@RequestMapping(value = "/authority", method = RequestMethod.GET)
	// @Permission
	public Object routes(@RequestParam(required = false) Integer type) {

		Map<String, List<String>> menus = iRoutesService.selectMenuMap(type);
		return SuccessTip.buildSuccess(menus);
	}

}
